<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="x-ua-compatible" content="IE=Edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>Rappid - Demo - highlighters.stroke</title>
    <link rel="stylesheet" type="text/css" href="../../css/lib/joint.min.css">
    <style>
        html, body, #paper {
            position: relative;
            overflow: hidden;
            padding: 0;
            margin: 0;
        }
        body {
            box-sizing: border-box;
            padding: 20px;
        }
        #paper {
            width: 400px;
            height: 300px;
            background-color: #fff;
            background-image: url('');
            background-repeat: repeat;
            box-shadow: 0 0 3px #888;
        }
    </style>
</head>
<body>

    <p>Click an element to highlight it. Click a blank area of the paper to unhighlight all elements.</p><br>
    <div id="paper"></div>

    <!-- JointJS/Rappid dependencies: -->
    <script src="../../js/lib/jquery.min.js"></script>
    <script src="../../js/lib/lodash.min.js"></script>
    <script src="../../js/lib/backbone.min.js"></script>

    <script src="../../js/lib/joint.min.js"></script>

    <script>
        document.addEventListener('DOMContentLoaded', function() {

            var rect1 = new joint.shapes.basic.Rect({
                position: { x: 50, y: 50 },
                size: { width: 80, height: 60 },
                attrs: {
                    rect: {
                        fill: '#D4A190'
                    }
                }
            });

            var rect2 = new joint.shapes.basic.Rect({
                position: { x: 150, y: 150 },
                size: { width: 40, height: 40 },
                attrs: {
                    rect: {
                        fill: '#A1D490'
                    }
                }
            });

            var graph = new joint.dia.Graph;
            var $paper = $('#paper');

            var paper = new joint.dia.Paper({
                el: $paper,
                width: $paper.width(),
                height: $paper.height(),
                model: graph,
                highlighting: {
                    'default': {
                        name: 'stroke',
                        options: {
                            padding: 5,
                            rx: 3,
                            ry: 3,
                            attrs: {
                                'stroke-width': 3,
                                stroke: '#C390D4'
                            }
                        }
                    }
                }
            });

            graph.addCells(rect1, rect2);

            var highlightedCellViews = [];

            paper.on('cell:pointerclick', function(cellView) {
                cellView.highlight();
                highlightedCellViews.push(cellView);
            });

            paper.on('blank:pointerclick', function(cellView) {
                // Unhighlight all cells.
                for (var i = 0; i < highlightedCellViews.length; i++) {
                    highlightedCellViews[i].unhighlight();
                }
            });
        });
    </script>

</body>
</html>
